<?php 
//引进配置信息
include '../include/init.php';
//引入数据库配置信息
include '../include/mysql.config.php';
//引入公共函数
include '../include/common.fun.php';
islogin();
include '../data/admin_data.php';
if($_POST){
	$idarr = $_POST['idarr'];
	if ($idarr) {
		foreach ($idarr as $v) {
			$tmp=$db->getOne("SELECT * from wd_case where case_id=".$v);
			$res=$db->delete('wd_case','case_id='.$v);
			if ($res) {
				unlink(SERVICE_PATH_CASE.$tmp['case_img']);
				unlink(SERVICE_PATH_CASE_THUMB.$tmp['case_img_thumb']);
			}
		}
		alert('删除成功','case_list.php');
	}
}

$current=isset($_GET['page'])?$_GET['page']:1;
if (isset($_GET['cid'])&&($_GET['cid']>0)) {
	$cid=$_GET['cid'];
	$where=" wd_case.case_cat_id={$cid} ";
}else{
	$cid=0;
	$where=1;
}

if (isset($_GET['search'])&&$_GET['search']) {
	$search=$_GET['search'];
	$where.=" AND wd_case.case_name like '%{$search}%' ";
}

$sql="SELECT COUNT(case_id) as count from wd_case where $where";
$case_list=$db->getOne($sql);
$count=$case_list['count'];

$limit=5;
$start=($current-1)*$limit;
$page = new Page($current,$count,$limit,5);
$page_link = $page->first()->prev()->num()->next()->show();

$sql="SELECT * from wd_case LEFT JOIN wd_case_cat ON wd_case.case_cat_id=wd_case_cat.case_cat_id where $where order by case_id desc limit $start,$limit";
$case=$db->getAll($sql);

$sql = "SELECT * FROM wd_case_cat";
$cat = $db->getAll($sql);

include 'view/case_list.php';